<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			#box{
				width: 100px;
				height: 100px;
				background: red;
			}
		</style>
		<script type="text/javascript">
			onload = function(){
				var oInput = document.getElementsByTagName("input")[0];
				var oBox   = document.getElementById("box");
				oInput.onclick = function(){
					//修改宽，高
					startMove(oBox,"height",400);
				}
				
				function startMove(obj,attr,iTarget){
					//1.关闭旧的定时器
					clearInterval(obj.timer);
					
					//2.开启新的定时器
					obj.timer = setInterval(function(){
						//1.获取当前值
						var current = parseInt(getStyleAttr(obj,attr));
						
						//2.给一个速度
						var iSpeed = (iTarget - current)/8;
						iSpeed = iSpeed > 0 ? Math.ceil(iSpeed) : Math.floor(iSpeed);
						
						//3.判断临界值
						if(current == iTarget){
							clearInterval(obj.timer);
							return;
						}
						
						//4.运动
						obj.style[attr] = current + iSpeed + "px";
						
					},30);
					
				}
				
				
				//获取元素节点的某个值
			/**
			 * 
			 * @param {Object} 需要获取属性值的元素节点，oBox
			 * @param {Object} 需要获取的属性，“left”
			 */
			function getStyleAttr(obj,attr){
				if(window.getComputedStyle){
					return getComputedStyle(obj,null)[attr];
				}
				return obj.currentStyle[attr];
			}
			}
		</script>
	</head>
	<body>
		<input type="button" value="改变宽度" />
		<div id="box"></div>
	</body>
</html>
